import pandas as pd
import numpy as np
from scipy import stats

def process(df: pd.DataFrame, threshold: float = 3.0) -> pd.DataFrame:
    '''使用Z-score方法处理离群值'''
    try:
        # 确保数据为数值类型
        values = pd.to_numeric(df.iloc[:, 1], errors='coerce')
        if values.isna().any():
            raise ValueError("存在无法转换为数值的数据")
            
        z_scores = np.abs(stats.zscore(values))
        df = df[z_scores <= threshold]
        print(f"del_zscore: 删除了{len(z_scores) - len(df)}个离群值")
        return df
    except Exception as e:
        print(f"Z-score处理错误: {str(e)}")
        return None 